<template>
	<view class="page">
		<view class="top">
			<view class="top_left">
				<view class="name">{{info.circle_name}}</view>
				<view class="desc">
					<view>{{info.like_num}}人想去</view>
					<view class="classify">{{info.label_name}}</view>
				</view>
				<view class="rank" @click="navrank">
					{{info.city_name}}商圈人气榜第{{info.rownum<100 ?info.rownum:99+'+'}}名
				</view>
			</view>
			<view @click="wantWalk" :class="info.is_like==0 ? 'top_right':'top_right none_btn'">
				想去
			</view>
		</view>
		<view class="center">
			<view class="center_left">
				<view class="address">{{info.shengshiqu+info.address}}</view>
				<view class="distance">距离您当前位置{{info.distance}}</view>
			</view>
			<image @click="openMap" src='../../../static/images/img/nav.png'></image>
		</view>
		<view class="rank_class">
			<view :class="actClassIndex == index ?'act_class rank_class-item': 'rank_class-item'" @click="setClassifyIndex(index)" v-for="(item,index) in classify">
				{{item.cate_name}}
			</view>
		</view>
		<scroll-view class="works" scroll-y @scrolltolower='bottomScroll' >
			<view class="works_center">
					<view v-for="(item,index) in works">
						<view :class='index%2 == 0 ? "item":"item_right item"' @click="navPlayer(index,item.circle_name)">
							<image :src='item.cover_img'></image>
							<view class="like_box">
								<view class="left">
									{{item.shop_name}}
								</view>
								<view class="right">
									<image src="../../../static/images/img/like_live.png"></image>
									<view>{{item.praise_num}}</view>
								</view>
							</view>
							<view class="address">
								<image src="../../../static/images/shop_area.png"></image>
								<view>{{item.shengshiqu +item.address}}</view>
							</view>
						</view>
					</view>
			</view>
					<uniLoadMore :loadingType='loadingType'></uniLoadMore>
		</scroll-view>
	
	</view>
</template>

<script>
	import circleItem from '../../../components/circleItem.vue'
	import uniLoadMore from "../../../components/uni-load-more.vue"
	export default {
		data() {
			return {
				works:[],
				info:{},
				circle_id:'',
				classify:[],
				page:1,
				loadingType:0,
				actClassIndex: 0,
				cateId: 0
				
			}
		},
		components:{
			circleItem,
			uniLoadMore
		},
		created() {
			
		},
		methods: {
			setClassifyIndex(index){
				if(this.actClassIndex != index){
					this.actClassIndex = index
					this.works = []
					uni.showLoading({
						title:'加载中'
					})
					this.initData(this.circle_id)
				}
			},
			navPlayer(index,circleName){
				console.log(this)
				this.$store.commit('setPlayList',this.works)
				uni.navigateTo({
					url:'../../circlePlayer/circlePlayer?id='+this.circle_id+'&index='+index + '&name='+circleName+'&cateId='+this.cateId+'&page='+this.page,
					fail: (err) => {
						console.log(err)
					}
				})
			},
			initData(circle_id){
				this.cateId = this.classify[this.actClassIndex].id
				this.$http.getcircle_video({
					 circle_id,
					 page:this.page,
					 cate_id:  this.cateId|| 0
				}).then(res=>{
					 if(res.status == 200){
						 this.works = this.works.concat(res.data)
						 if(res.data.length == 0){
							 this.page = --this.page
							 this.loadingType = 2
						 }
						 this.loadingType = 0
						 
					 }
					 uni.hideLoading()
				})
			},
			initDetail(circle_id){
				this.$http.circle_details({
					circle_id
				}).then(res=>{
					console.log(res)
					uni.setNavigationBarTitle({
						title:res.data.circle_name
					})
					this.info =res.data
					uni.hideLoading()
				})
			},
			navrank(){
				uni.navigateTo({
					url:'../shopCircle/shopCircle?city='+this.info.city_name
				})
			},
			bottomScroll(){
				this.page = ++this.page
				this.loadingType = 1
				this.initData(this.circle_id)
			},
			wantWalk(){
				uni.showLoading({
					// title:'请求中'
				})
				this.$http.circlelike({
					circle_id: this.circle_id,
					islike: this.info.is_like
				}).then(res=>{
					console.log(res)
					if(res.status == 200){
						if(this.info.is_like == 0){
							uni.showToast({
								title:'关注成功',
								icon:'none',
							})
						}else{
							uni.showToast({
								title:'成功取消',
								icon:'none',
							})
						}
						this.info.is_like = this.info.is_like == 0 ? 1:0
					}
					uni.hideLoading()
				})
			},
			openMap(){
			
				let [latitude,longitude] = this.info.lon_lat.split(',')
				 latitude  = parseFloat(latitude) 
				 longitude = parseFloat(longitude)
				console.log(latitude,longitude) 
				  wx.openLocation({
					 latitude,
					 longitude,
					 scale: 18
				   })
			
			  },
		},
		onLoad(options){
			uni.showLoading({
				title:'加载中'
			})
			console.log(options)
			let id = options.id
			this.circle_id = id
			this.classify = this.$store.getters.getClassify
			
			if(!this.classify.find(item=>{
				return item.cate_name == '全部'
			})){
				this.classify.unshift({
					cate_name: '全部',
					pid:0,
					id: 0
				})
			}
			this.initDetail(id)
			this.initData(id)
		}
	}
</script>

<style lang="less">
	.page{
		background-color: #0F111D;
		height: 100vh;
		overflow: hidden;
		.top{
			display: flex;
			align-items: flex-end;
			padding: 20rpx 3vw;
			justify-content: space-between;
			.top_left{
				.name{
					font-size: 48rpx;
					color: #ffffff;
				}
				.desc{
					display: flex;
					color: #999999;
					margin: 40rpx 0;
					.classify{
						margin-left: 15rpx;
					}
				}
				.rank{
					color: #ffd201;
					position: relative;
					&::after{
						content: '';
						position: absolute;
						width: 7px;
						height: 7px;
						top: 10rpx;
						border-top: 2px solid #ffd201;
						border-right: 2px solid #ffd201;
						transform: rotate(45deg);
					}
				}
			}
			.top_right{
				width: 160rpx;
				height: 60rpx;
				background-color: #ff3d3d;
				border-radius: 5rpx;
				color: #fff;
				line-height: 60rpx;
				text-align: center;
			}
			.none_btn{
				background-color: #666666;
				color: #000;
			}
		}
		.center{
			height: 110rpx;
			background-color: #242730;
			border-radius: 10rpx;
			width: 94vw;
			margin: 20rpx 3vw;
			display: flex;
			align-items: center;
			justify-content: space-between;
			padding:0 3vw;
			.center_left{
				display: flex;
				flex-direction: column;
				justify-content: space-around;
				height: 100rpx;
				// flex: 1;
				.address{
					color: #ffffff;
					font-size: 30rpx;
				}
				.distance{
					color: #999999;
					font-size: 24rpx;
				}
			}
			image{
				width: 34rpx;
				height: 34rpx;
			}
			
		}
		.rank_class{
			display: flex;
			text-align: center;
			color: white;
			width: 94vw;
			margin-left: 3vw;
			overflow-y: auto;
			display: flex;
			margin-top: 20rpx;
			.rank_class-item{
				display: inline;
				margin: 0 20rpx 0 0;
				font-size: 24rpx;
				flex-shrink: 0;
				line-height: 36rpx;
				// width: 80rpx;
				height: 50rpx;
				background-color: #242730;
				border-radius: 5rpx;
				color: #999999;
				padding: 8rpx 12rpx;
			}
			.act_class{
				color: #ffffff;
			}
		}
		.works{
			margin: 20rpx 3vw;
			width: 94vw;
			height: calc(100vh - 402rpx);
			overflow-y: scroll;
		
			.hint{
				font-size: 30rpx;
				color: #fffefe;
			}
			.works_center{
				display: flex;
				flex-wrap: wrap;
				padding-bottom: 40rpx;
				position: relative;
				.item{
					margin-right: 2vw;
					margin-top: 15rpx;
						position: relative;
					.item_right{
						margin-right: 0;
						margin-left: 2vw;
							position: relative;
					}
					image{
						width: 45vw;
						height: 50vw;
						display: block;
					}
					view{
						position: relative;
					}
					.like_box{
						position: absolute;
						left: 0rpx;
						padding: 0 12rpx;
						top: calc(50vw - 60rpx);
						color: #fff;
						font-size: 24rpx;
						display: flex;
						align-items: center;
						height: 55rpx;
						display: flex;
						align-items: center;
						justify-content: space-between;
						width: 100%;
						.right{
							display: flex;
							align-items: center;
						}
						image{
							width: 21rpx;
							height: 18rpx;
							z-index: 2;
							margin-right: 5rpx;
						}
					}
					.address{
						width: 45vw;
						// flex: 1;
						padding: 10rpx 12rpx;
						color: #fff;
						background-color: #242730;
						display: flex;
						// height: 90rpx;
						image{
							width: 20rpx;
							height: 24rpx;
							margin-top: 5rpx;
							margin-right: 10rpx;
						}
						view{
							// width: 90%;
							flex: 1;
							
						}
					}
				}
			}
		}
		::-webkit-scrollbar {display:none}
	}
</style>
